<?php

namespace App\Ad\MediaApi\Gdt;

class GdtZhgyApi extends GdtApiBase
{
    /**
     * APP转化数据API自归因
     * https://developers.e.qq.com/docs/guide/conversion/new_version/APP_api
     * @param string    $url
     * @param array     $data
     * @return boolean
     */
    public function sendConv($url, $actions)
    {
        $headers = [
            'Content-Type: application/json',
            'cache-control: no-cache',
        ];
        $data = [
            'actions' => [$actions],
        ];
        $params = json_encode($data, JSON_UNESCAPED_UNICODE);

        $res = $this->curl($url, $params, true, true, 30, false, $headers);
        if ($res[0] != 200) {
            yqlog($url, $data, $res);
            return false;
        }

        $res = json_decode($res[1], true);
        if ($res['code'] != 0) {
            yqlog($url, $data, $res);
            return false;
        }

        return true;
    }
}
